import request from "@/utils/request.ts";
import { ICommonResponse } from '@/global.ts'

// 发送邮件
export const emailCode = (data: { email: string, mode: string }): Promise<ICommonResponse<any>> => {
    return request({
        url: '/email',
        method: 'POST',
        data
    })
}
// 注册
export const register = (data: { email: string, mode: string, code: string }): Promise<ICommonResponse<{ msg: string }>> => {
    return request({
        url: '/register',
        method: 'POST',
        data
    })
}
// 重置密码
export const reset = (data: { email: string, mode: string, code: string, password: string }): Promise<ICommonResponse<any>> => {
    return request({
        url: '/reset',
        method: 'POST',
        data
    })
}
interface ILoginResponse {
    msg: string
    token: string
    info: IUser
}
// 密码登录
export const passwordLogin = (data: { email: string, password: string }): Promise<ICommonResponse<ILoginResponse>> => {
    return request({
        url: '/password/login',
        method: 'POST',
        data
    })
}
// 验证码登录
export const codeLogin = (data: { email: string, code: string, mode: string }): Promise<ICommonResponse<ILoginResponse>> => {
    return request({
        url: '/email/login',
        method: 'POST',
        data
    })
}
export interface IUser {
    userUID: string
    email: string
    secretKey: string
    name: string
    role: string
    profile: string
}
// token获取用户信息
export const tokenInfo = (): Promise<ICommonResponse<IUser>> => {
    return request({
        url: '/token/info',
        method: 'POST'
    })
}

